home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / PTR-TCL v2.1 / 3) inherited fixer / main.c < prev    next >
Text File  |  1994-01-15  |  3KB  |  181 lines

  1. /*
  2.  * main.c
  3.  */
  4.  
  5. extern short ReadClasses ( unsigned char * name ) ;
  6.  
  7. void Idle ( void ) ;
  8. void Message ( unsigned char * ) ;
  9. void Try ( short code ) ;
  10.  
  11. unsigned char * folder_to_munge = "\pTO MUNGE" ;
  12. unsigned char * message_file = "\pMESSAGES" ;
  13. unsigned char * class_file = "\p CLASSLIST" ;
  14.  
  15. Handle windowText = NULL ;
  16. WindowPtr window = NULL ;
  17. short vRefNum = 0 ;
  18. Boolean done = 0 ;
  19.  
  20.  
  21. extern void MungeFolder ( long parID ) ;
  22.  
  23.  
  24. void
  25. Try ( short code ) {
  26.  
  27.     if ( code ) {
  28.         DebugStr ( "\pFailure!" ) ;
  29.     }
  30. }
  31.  
  32.  
  33. static void
  34. InitMac ( ) {
  35.     InitGraf ( & qd . thePort ) ;
  36.     InitFonts ( ) ;
  37.     InitWindows ( ) ;
  38.     InitMenus ( ) ;
  39.     TEInit ( ) ;
  40.     InitDialogs ( NULL ) ;
  41. }
  42.  
  43.  
  44. static void
  45. UpdateWindow ( ) {
  46.  
  47. Rect r = window -> portRect ;
  48.  
  49.     InsetRect ( & r , 3 , 3 ) ;
  50.     TextFont ( GetAppFont ( ) ) ;
  51.     TextSize ( GetDefFontSize ( ) ) ;
  52.     HLock ( windowText ) ;
  53.     TextBox ( * windowText , GetHandleSize ( windowText ) , & r , teJustLeft ) ;
  54.     HUnlock ( windowText ) ;
  55. }
  56.  
  57.  
  58. static void
  59. Click ( EventRecord * er ) {
  60.  
  61. WindowPtr win ;
  62. short code ;
  63. Rect limit = ( * GetGrayRgn ( ) ) -> rgnBBox ;
  64.  
  65.     InsetRect ( & limit , 3 , 3 ) ;
  66.     code = FindWindow ( er -> where , & win ) ;
  67.     switch ( code ) {
  68.     case inSysWindow :
  69.         SystemClick ( er , win ) ;
  70.         break ;
  71.     case inDrag :
  72.         DragWindow ( win , er -> where , & limit ) ;
  73.         break ;
  74.     }
  75. }
  76.  
  77.  
  78. void
  79. Idle ( ) {
  80. EventRecord er ;
  81.  
  82.     WaitNextEvent ( -1 , & er , 0L , NULL ) ;
  83.     switch ( er . what ) {
  84.     case mouseDown :
  85.         Click ( & er ) ;
  86.         break ;
  87.     case updateEvt :
  88.         SetPort ( window ) ;
  89.         BeginUpdate ( window ) ;
  90.         EraseRect ( & ( window -> portRect ) ) ;
  91.         UpdateWindow ( ) ;
  92.         EndUpdate ( window ) ;
  93.         break ;
  94.     }
  95. }
  96.  
  97.  
  98. static void
  99. SetWindowText ( unsigned char * string ) {
  100.  
  101.     PtrToXHand ( string + 1 , windowText , * string ) ;
  102.     SetPort ( window ) ;
  103.     UpdateWindow ( ) ;
  104. }
  105.  
  106.  
  107. void
  108. Message ( unsigned char * message ) {
  109.  
  110. static short refNum = 0 ;
  111. long len ;
  112. static unsigned long last = 0 ;
  113.  
  114.     do {
  115.         Idle ( ) ;
  116.     } while ( TickCount ( ) < last + 5 ) ;
  117.     last = TickCount ( ) ;
  118.  
  119.     if ( ! message ) {
  120.         if ( refNum ) {
  121.             FSClose ( refNum ) ;
  122.             FlushVol ( NULL , 0 ) ;
  123.         }
  124.         refNum = 0 ;
  125.         return ;
  126.     }
  127.     if ( ! refNum ) {
  128.         Create ( message_file , 0 , 'MPS ' , 'TEXT' ) ;
  129.         Try ( FSOpen ( message_file , 0 , & refNum ) ) ;
  130.         Try ( SetEOF ( refNum , 0L ) ) ;
  131.     }
  132.     if ( refNum ) {
  133.         len = * message ;
  134.         Try ( FSWrite ( refNum , & len , message + 1 ) ) ;
  135.     }
  136.     SetWindowText ( message ) ;
  137. }
  138.  
  139.  
  140. static void
  141. MakeWindow ( ) {
  142.  
  143.     window = GetNewWindow ( 128 , NULL , NULL ) ;
  144.     if ( ! window ) {
  145.         Try ( -192 ) ;
  146.     }
  147.     windowText = NewHandle ( 0L ) ;
  148.     Message ( "\pWelcome!\r" ) ;
  149.     SelectWindow ( window ) ;
  150.     ShowWindow ( window ) ;
  151. }
  152.  
  153.  
  154. void
  155. main ( ) {
  156.  
  157. CInfoPBRec rec ;
  158.  
  159.     InitMac ( ) ;
  160.     MakeWindow ( ) ;
  161.  
  162.     if ( ! ReadClasses ( class_file ) ) {
  163.  
  164.         rec . hFileInfo . ioNamePtr = folder_to_munge ;
  165.         rec . hFileInfo . ioVRefNum = 0 ;
  166.         rec . hFileInfo . ioDirID = 0 ;
  167.         rec . hFileInfo . ioFDirIndex = 0 ;
  168.         Try ( PBGetCatInfoSync ( & rec ) ) ;
  169.         if ( rec . hFileInfo . ioFlAttrib & 0x10 ) {    
  170.             MungeFolder ( rec . hFileInfo . ioDirID ) ;
  171.         } else {
  172.             Message ( "\pIt's not a folder!" ) ;
  173.         }
  174.     } else {
  175.         Message ( "\pCannot open class file" ) ;
  176.     }
  177.     Message ( "\pClick To Exit\r" ) ;
  178.     Message ( NULL ) ;
  179.     Idle ( ) ;
  180. }
  181.